import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.stream.Stream;

/**
 * Stream流中间方法
 */
public class MiddleMethodDemo {
    public static void main(String[] args) {

        ArrayList<String> list1 = new ArrayList<>(Arrays.asList("张三丰", "张无忌", "张翠山", "王二麻子", "张良", "谢广坤"));
        ArrayList<String> list2 = new ArrayList<>(Arrays.asList("张三丰", "张无忌"));
        // filter,过滤操作
        System.out.println("===================================");
        list1.stream().filter(s -> s.startsWith("张")).forEach(System.out::println);

        // limit,截取制定参数个数的数据
        System.out.println("===================================");
        list1.stream().limit(2).forEach(System.out::println);

        // skip,跳过制定参数个数的数据
        System.out.println("===================================");
        list1.stream().skip(2).forEach(System.out::println);

        // concat,合并两个流为一个流
        System.out.println("===================================");
        Stream.concat(list1.stream(),list2.stream()).forEach(System.out::println);

        // distinct,去除流中重复的元素
        System.out.println("===================================");
        Stream.concat(list1.stream(),list2.stream()).distinct().forEach(System.out::println);

    }
}
